﻿using System;
using Epm.AppLogic.Framework;
using msBsc.Xsd.DataTds;
using System.Data;
using System.Linq;
using msBsc.AppLogic.DataAlc.cls;
using msBsc.Cls;

namespace msBsc.AppLogic.DataAlc
{
    public class CBizDjackSpecieInfo : CustBizObject
    {
        private CDmDjkDjackSpecieInfo m_CDmDjkDjackSpecieInfo = new CDmDjkDjackSpecieInfo();
        private CDmDjkDjackSpecieInfo oDmDjkDjackSpecieInfo
        {
            get { return m_CDmDjkDjackSpecieInfo; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public CBizDjackSpecieInfo()
            : base()
        {
            this.DataObj = new CDbAccess();
            this.DataObj.Init(this.m_CDmDjkDjackSpecieInfo.DJK_DJACK_SPECIEINFO);
            this.TableName = this.DataObj.TableName;
            this.DataObj.KeyField = this.DataObj.Fields["DJACK_SPECIEINFO_ID"];
        }

        public CBizDjackSpecieInfo(string QueryString)
            : base()
        {
            this.DataObj = new CDbAccess();
            this.DataObj.Init(this.m_CDmDjkDjackSpecieInfo.DJK_DJACK_SPECIEINFO);
            this.TableName = this.DataObj.TableName;
            this.DataObj.KeyField = this.DataObj.Fields["DJACK_SPECIEINFO_ID"];
            SetQueryStr(QueryString);
        }
        /// <summary>
        /// 新增记录前的处理
        /// </summary>
        /// <param name="drw">新增数据行</param>
        /// <returns>true/false</returns>
        /// <remarks>
        /// 生成ID值
        /// </remarks>
        protected override bool BeforeRowAdded(DataRow drw)
        {
            if (drw[this.KeyFieldName].ToString().Length < 10)
            {
                drw[this.KeyFieldName] = this.DataObj.NewID();
            }
            return true;
        }

        /// <summary>
        /// 记录修改前检验
        /// </summary>
        /// <param name="drw">当前记录</param>
        /// <returns>>校验合法，返回值为true,否则返回false</returns>
        /// <remarks>
        /// ID不允许修改,并把此修改操作记录到BSE_MODIFY_HISTORY表中
        /// </remarks>
        protected override bool BeforeRowModified(DataRow drw)
        {
            //ID不容许修改
            if (drw[this.KeyFieldName].ToString() != drw[this.KeyFieldName, DataRowVersion.Original].ToString())
            {
                Exception e = new Exception(this.TableName + "表的主键" + this.KeyFieldName + "字段不允许被修改");
                throw e;
            }
            #region 修改地接客信息格式验证
            if (drw["DJACK_INTRODUCE"].ToString().Length > 1000)
            {
                Exception e = new Exception("简介过长");
                throw e;
            }
            #endregion
            return true;
        }
        protected override bool BeforeRowDeletedR(DataRow drw)
        {
            //using (msBsc.AppLogic.DataAlc.CBizShpPageColumn objtem = new CBizShpPageColumn())
            //{
            //    DataSet ds = objtem.SelectByPageNo(this.GetRowStr(drw, KeyFieldName));
            //    for (int i = ds.Tables[0].Rows.Count - 1; i >= 0; i--)
            //    {
            //        ds.Tables[0].Rows[i].Delete();
            //    }
            //    objtem.Update(ds);
            //} 
            return true;
        }

        protected override bool AfterRowAdded(DataRow drw)
        {
            return true;
        }

        protected override bool AfterRowModified(DataRow drw)
        {
            return true;
        }

        protected override bool AfterRowDeletedR(DataRow drw)
        {
            return true;
        }

        #region 成为地接客处理
        /// <summary>
        /// 成为地接客处理
        /// </summary>
        /// <param name="id">用户编号</param>
        /// <param name="djackServiceType">地接客服务类型</param>
        /// <param name="selfIntroduce">地接客自我简介</param>
        // /// <param name="tradingAccount">交易账号</param>
        /// <param name="travelAdvice">旅游推荐</param>
        /// <param name="credentialsNum">证件号码</param>
        /// <param name="gender">性别</param>
        /// <param name="mobilePhone">移动电话</param>
        /// <param name="name">姓名</param>
        /// <param name="phone">固定电话</param>
        /// <param name="email">邮箱</param>
        /// <param name="headPhotoName">头像</param>
        /// <param name="distinId">所在地编号</param>
        /// <param name="cityId">所在城市编号</param>
        /// <param name="countryId">所在国家编号</param>
        /// <param name="nickName">昵称</param>
        /// <param name="serviceLabel">服务标签</param>
        /// <param name="tencentQq">QQ</param>
        /// <param name="weChat">微信</param>
        /// <param name="credentialType">证件类型</param>
        public string[] BecomeDjack(string id, int djackServiceType, string selfIntroduce, string phone, string mobilePhone, string name, string gender, string credentialsNum, string headPhotoName, string nickName, string distinId, string cityId, string countryId, string serviceLabel, string tencentQq, string email, string weChat, msBsc.AppLogic.DataAlc.cls.CommonEnum.CredentialsTypeEnum credentialType)
        {
            #region 验证信息合法性
            //判断是否满足成为地接客条件
            if (!IsHasUser(id) ||
                string.IsNullOrEmpty(mobilePhone) ||
                string.IsNullOrEmpty(nickName) ||
                string.IsNullOrEmpty(email))
            {
                return new string[] { "FALSE", "信息不能为空" };
            }

            #region 长度合法性验证
            if (selfIntroduce.Length > 240)
            {
                return new string[] { "FALSE", "自我简介过长" };
            }
            if (CommValiCollection.GetStrLength(nickName) > 100)
            {
                return new string[] { "FALSE", "昵称过长" };
            }
            //if (gender.ToUpper() != "M" && gender.ToUpper() != "F")
            //{
            //    return new string[] { "FALSE", "性别格式不正确" };
            //}
            //if (CommValiCollection.GetStrLength(tradingAccount) > 50)
            //{
            //    return new string[] { "FALSE", "交易帐号过长" };
            ////}
            //if (!string.IsNullOrEmpty(phone) && !CommValiCollection.IsTell(phone))
            //{
            //    return new string[] { "FALSE", "固定电话格式不正确" };
            //}
            //if (!CommValiCollection.IsMobile(mobilePhone))
            //{
            //    return new string[] { "FALSE", "手机号码格式不正确" };
            //}
            if (name.Length > 15)
            {
                return new string[] { "FALSE", "姓名过长" };
            }
            if (CommValiCollection.GetStrLength(headPhotoName) > 100)
            {
                return new string[] { "FALSE", "头像名称过长" };
            }
            if (!string.IsNullOrEmpty(tencentQq) && !CommValiCollection.IsQQ(tencentQq))
            {
                return new string[] { "FALSE", "QQ格式不正确" };
            }
            #endregion


            #endregion

            #region 获取用户注册信息并进行比较
            //获取用户注册信息
            DataSet dsRegister1 = GetUserRegisterInfoById(id);
            if (dsRegister1 == null || dsRegister1.Tables[0].Rows.Count < 1)
            {
                return new string[] { "FALSE", "没有该用户" };
            }
            DataSet dsName = IsNickNameUniques(nickName, id);
            if (dsName.Tables[0].Rows.Count > 0)
            {
                return new string[] { "FALSE", "该昵称已存在" };
            }
            DataRow drRegister1 = dsRegister1.Tables[0].Rows[0];
            //获取验证结果
            int urResult1 = ConfirmRegisterInfo(dsRegister1, headPhotoName, nickName);
            //判断验证结果
            if (urResult1 == -10)//未激活账号
            {
                return new string[] { "FALSE", "未激活账号" };
            }
            #endregion

            #region 验证账户是否可成为地接客
            //获取用户信息
            DataSet dsBase1 = GetBaseInfoById(id);
            if (dsBase1 == null || dsBase1.Tables[0].Rows.Count < 1)
            {
                return new string[] { "FALSE", "没有该用户" };
            }
            DataSet dsSpecie = SelectDjackById(id);
            if (Convert.ToInt32(drRegister1["CUSTOMER_ACCOUNT_TYPE"]) == (int)msBsc.AppLogic.DataAlc.cls.CommonEnum.AccountTypeEnum.地接客 || (dsSpecie != null && dsSpecie.Tables[0].Rows.Count > 0))
            {
                return new string[] { "FALSE", "您已是地接客,无需重复申请" };
            }
            if (Convert.ToInt32(drRegister1["CUSTOMER_ACCOUNT_TYPE"]) != (int)msBsc.AppLogic.DataAlc.cls.CommonEnum.AccountTypeEnum.游客)
            {
                return new string[] { "FALSE", "只有游客才能成为地接客" };
            }
            #endregion
            System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
            transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            transactionOption.Timeout = new TimeSpan(0, 10, 0);
            using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
            {
                //此处添加用户自己的逻辑代码
                //更新注册表
                using (CBizCustomerRegister objCustomerRegister = new CBizCustomerRegister())
                {
                    drRegister1["CUSTOMER_DEFAULT_PIC"] = headPhotoName;
                    drRegister1["CUSTOMER_NICK"] = nickName;
                    drRegister1["CUSTOMER_ACCOUNT_TYPE"] = (int)msBsc.AppLogic.DataAlc.cls.CommonEnum.AccountTypeEnum.地接客;
                    objCustomerRegister.Update(dsRegister1);
                }

                //更新基本信息
                using (CBizCustomerBaseInfo objCustomerBaseInfo = new CBizCustomerBaseInfo())
                {

                    DataRow drBase1 = dsBase1.Tables[0].Rows[0];
                    drBase1["CUSTOMER_BASEINFO_PHONE"] = string.IsNullOrEmpty(phone) ? "" : phone;
                    drBase1["CUSTOMER_BASEINFO_MOBILE"] = string.IsNullOrEmpty(mobilePhone) ? "" : mobilePhone;
                    drBase1["CUSTOMER_BASEINFO_NAME"] = name;
                    drBase1["CUSTOMER_BASEINFO_INTRO"] = string.IsNullOrEmpty(selfIntroduce) ? "" : selfIntroduce;
                    drBase1["CUSTOMER_BASEINFO_GENDER"] = gender.ToUpper();
                    drBase1["CUSTOMER_CREDENTIALS_NO"] = credentialsNum;
                    drBase1["CUSTOMER_DISTINATION_ID"] = distinId;
                    drBase1["CUSTOMER_CITY_ID"] = cityId;
                    drBase1["CUSTOMER_COUNTRY_ID"] = countryId;
                    drBase1["CUSTOMER_BASEINFO_QQ"] = tencentQq;
                    drBase1["CUSTOMER_BASEINFO_EMAIL"] = email;
                    drBase1["CUSTOMER_WECHAT_NO"] = weChat;
                    drBase1["CUSTOMER_CREDENTIALS_TYPE"] = (int)credentialType;
                    objCustomerBaseInfo.Update(dsBase1);
                }

                using (DataSet dsDjk = new CDmDjkDjackSpecieInfo())
                {
                    DataRow drDjk = dsDjk.Tables[0].NewRow();
                    drDjk["BECOME_DJACK_TIME"] = this.dtCurrDateTime;
                    drDjk["DJACK_SERVICE_TYPE"] = djackServiceType;
                    drDjk["DJACK_INTRODUCE"] = string.IsNullOrEmpty(selfIntroduce) ? "" : selfIntroduce;
                    drDjk["DJACK_SCAN_NUM"] = 0;
                    drDjk["DJACK_SPECIEINFO_ID"] = id;
                    drDjk["DJACK_IS_CERTIFICATION"] = 0;
                    drDjk["DJACK_ACCOUNT_BALANCE"] = 0;
                    drDjk["DJACK_TRANS_COUNT"] = 0;
                    drDjk["SPECIE_IS_DELETED"] = 0;
                    dsDjk.Tables[0].Rows.Add(drDjk);
                    this.Update(dsDjk);
                }

                if (string.IsNullOrEmpty(serviceLabel))
                {
                    string[] sArray = serviceLabel.Split('|');
                    int[] iArray = new int[sArray.Length];
                    for (int i = 0; i < iArray.Length; i++)
                    {
                        int lab = 1;
                        int.TryParse(sArray[i], out lab);
                        iArray[i] = lab;
                    }
                    //添加服务标签
                    using (CBizServiceLable objServiceLable = new CBizServiceLable())
                    {
                        objServiceLable.InsertDjackServiceLabel(iArray, id);
                    }
                }
                ts.Complete();
            }
            return new string[] { "TRUE", "申请成功" };
        }
        #endregion

        #region 修改地接客信息
        /// <summary>
        /// 修改地接客
        /// </summary>
        /// <param name="djkId">地接客ID</param>
        /// <param name="nickName">昵称</param>
        /// <param name="picture">头像</param>
        /// <param name="sex">性别</param>
        /// <param name="intro">简介</param>
        /// <param name="distinid">所属地ID</param>
        /// <param name="cityid">所属城市ID</param>
        /// <param name="countryid">所属国家ID</param>
        /// <param name="mobile">手机</param>
        /// <param name="phone">座机</param>
        /// <param name="qq">qq</param>
        /// <param name="wechat">微信</param>
        /// <param name="email">邮箱</param>
        /// <returns></returns>
        public string[] EditDjack(string djkId, string nickName, string picture, string sex, string intro, string distinid, string cityid, string countryid, string mobile, string phone, string qq, string wechat, string email)
        {
            #region 基本验证
            if (string.IsNullOrEmpty(djkId) ||
                string.IsNullOrEmpty(nickName) ||
                string.IsNullOrEmpty(intro) ||
                string.IsNullOrEmpty(mobile) ||
                string.IsNullOrEmpty(email))
            {
                return new string[] { "FALSE", "信息不能为空" };
            }
            if (!CommValiCollection.IsEmail(email) && email.Length > 50)
            {
                return new string[] { "FALSE", "邮箱不正确" };
            }
            if (!string.IsNullOrEmpty(qq) && !CommValiCollection.IsQQ(qq) && qq.Length > 15)
            {
                return new string[] { "FALSE", "QQ不正确" };
            }
            if (sex.ToUpper() != "M" && sex.ToUpper() != "F")
            {
                return new string[] { "FALSE", "性别不正确" };
            }
            if (mobile.Length > 20)
            {
                return new string[] { "FALSE", "手机不正确" };
            }
            if (!string.IsNullOrEmpty(phone) && phone.Length > 16)
            {
                return new string[] { "FALSE", "座机不正确" };
            }
            if (!string.IsNullOrEmpty(wechat) && wechat.Length > 30)
            {
                return new string[] { "FALSE", "微信不正确" };
            }
            if (nickName.Length > 50)
            {
                return new string[] { "FALSE", "昵称不正确" };
            }
            #endregion

            #region 修改信息
            //修改地接客特有信息
            DataSet ds = SelectDjackById(djkId);
            if (ds.Tables[0].Rows.Count <= 0)
            {
                return new string[] { "FALSE", "该地接客不存在" };
            }
            DataRow dr = ds.Tables[0].Rows[0];
            dr["DJACK_INTRODUCE"] = intro;
            this.Update(ds);

            //修改地接客基本信息
            using (CBizCustomerBaseInfo objCustomerBaseInfo = new CBizCustomerBaseInfo())
            {
                DataSet ds1 = objCustomerBaseInfo.SelectCustomerById(djkId);
                if (ds1.Tables[0].Rows.Count <= 0)
                {
                    return new string[] { "FALSE", "该地接客不存在" };
                }
                ds1.Tables[0].Rows[0]["CUSTOMER_BASEINFO_GENDER"] = sex;
                ds1.Tables[0].Rows[0]["CUSTOMER_BASEINFO_INTRO"] = intro;
                ds1.Tables[0].Rows[0]["CUSTOMER_DISTINATION_ID"] = distinid;
                ds1.Tables[0].Rows[0]["CUSTOMER_CITY_ID"] = cityid;
                ds1.Tables[0].Rows[0]["CUSTOMER_COUNTRY_ID"] = countryid;
                ds1.Tables[0].Rows[0]["CUSTOMER_BASEINFO_MOBILE"] = mobile;
                ds1.Tables[0].Rows[0]["CUSTOMER_BASEINFO_PHONE"] = phone;
                ds1.Tables[0].Rows[0]["CUSTOMER_BASEINFO_QQ"] = qq;
                ds1.Tables[0].Rows[0]["CUSTOMER_WECHAT_NO"] = wechat;
                ds1.Tables[0].Rows[0]["CUSTOMER_BASEINFO_EMAIL"] = email;
                objCustomerBaseInfo.Update(ds1);
            }

            //修改地接客注册信息
            using (CBizCustomerRegister objCustomerRegister = new CBizCustomerRegister())
            {
                DataSet ds2 = objCustomerRegister.SelectCustomerByRegisterId(djkId);
                if (ds2.Tables[0].Rows.Count <= 0)
                {
                    return new string[] { "FALSE", "该地接客不存在" };
                }
                DataSet dsName = objCustomerRegister.IsNickNameUnique(nickName, djkId);
                if (dsName.Tables[0].Rows.Count > 0)
                {
                    return new string[] { "FALSE", "该昵称已存在" };
                }
                ds2.Tables[0].Rows[0]["CUSTOMER_NICK"] = nickName;
                ds2.Tables[0].Rows[0]["CUSTOMER_DEFAULT_PIC"] = picture;
                objCustomerRegister.Update(ds2);
            }
            #endregion
            return new string[] { "TRUE", "修改成功" };
        }
        #endregion

        #region 地接客旅游推荐处理
        /// <summary>
        /// 设置旅游推荐
        /// </summary>
        /// <param name="djkId">地接客ID</param>
        /// <param name="travelAdvice">旅游推荐信息</param>
        /// <returns></returns>
        public string[] AddTravelAdvice(string djkId, string travelAdvice)
        {
            if (string.IsNullOrEmpty(djkId))
            {
                return new string[] { "FALSE", "地接客ID不能为空" };
            }
            if (string.IsNullOrEmpty(travelAdvice))
            {
                return new string[] { "FALSE", "推荐信息不能为空" };
            }
            DataSet ds = GetDjackByDjkId(djkId);
            if (ds.Tables[0].Rows.Count < 0)
            {
                return new string[] { "FALSE", "该地接客不存在" };
            }
            string strVpath = string.Empty;
            if (string.IsNullOrEmpty(ds.Tables[0].Rows[0]["DJACK_TRAVEL_ADVICE"].ToString()))
            {
                strVpath = msBsc.AppLogic.Cfg.SystemFileDir.FileDir.strSaveUploadSysFileDirV + this.DataObj.NewID() + ".html";//存储文件的虚拟路径

            }
            else
            {
                strVpath = ds.Tables[0].Rows[0]["ADVICE_HTML_URL"].ToString();
            }
            if (travelAdvice != string.Empty && strVpath != string.Empty)
            {
                string strFFullPath = System.Web.HttpContext.Current.Server.MapPath(strVpath);
                using (System.IO.TextWriter streamWriter = new System.IO.StreamWriter(strFFullPath))
                {
                    streamWriter.Write(travelAdvice);
                }
                ds.Tables[0].Rows[0]["ADVICE_HTML_URL"] = strVpath;
                //System.IO.File.WriteAllText(strFFullPath, strHeadHtml, System.Text.Encoding.UTF8);
            }
            this.Update(ds);
            return new string[] { "TRUE", "设置旅游推荐成功" };
        }

        #endregion

        #region 地接客查询信息处理
        /// <summary>
        /// 查询地接客信息
        /// </summary>
        /// <param name="djkId">地接客ID</param>
        /// <returns></returns>
        public DataSet SelectDjackById(string djkId)
        {
            if (string.IsNullOrEmpty(djkId))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("DJKID", ParameterDirection.Input, EDbType.String, 36, djkId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT DJACK_SPECIEINFO_ID,DJACK_INTRODUCE
    FROM DJK_DJACK_SPECIEINFO WHERE DJACK_SPECIEINFO_ID=@DJKID", parmCollection);
            ds.Tables[0].TableName = this.TableName;
            return ds;
        }

        /// <summary>
        /// 查询地接客详细信息
        /// </summary>
        /// <param name="djkId">地接客ID</param>
        /// <returns>DJACK_SPECIEINFO_ID：地接客ID，CUSTOMER_NICK：昵称，CUSTOMER_DEFAULT_PIC：头像，CUSTOMER_BASEINFO_GENDER：性别，CUSTOMER_INVITATION_CODE：邀请码，CUSTOMER_BASEINFO_MOBILE:移动电话，CUSTOMER_BASEINFO_PHONE:固定电话,CUSTOMER_BASEINFO_QQ：qq，CUSTOMER_WECHAT_NO：微信，CUSTOMER_BASEINFO_EMAIL：邮箱，DJACK_INTRODUCE：地接客简介，DISTINANAME：所属地名称，CITYNAME：所属城市名称，COUNTRYNAME：所在国家名称</returns>
        public DataSet GetDjackByIds(string djkId)
        {
            if (string.IsNullOrEmpty(djkId))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("DJKID", ParameterDirection.Input, EDbType.String, 36, djkId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT T2.*,F.COUNTRY_CITY_NME DISTINANAME FROM
    (SELECT T1.*,E.COUNTRY_CITY_NME CITYNAME FROM
    (SELECT T.*,D.COUNTRY_CITY_NME COUNTRYNAME FROM
    (SELECT A.DJACK_SPECIEINFO_ID, B.CUSTOMER_NICK,B.CUSTOMER_DEFAULT_PIC,
    B.CUSTOMER_INVITATION_CODE,C.CUSTOMER_BASEINFO_GENDER,
    C.CUSTOMER_DISTINATION_ID,C.CUSTOMER_CITY_ID,C.CUSTOMER_COUNTRY_ID,
    C.CUSTOMER_BASEINFO_MOBILE,C.CUSTOMER_BASEINFO_PHONE,C.CUSTOMER_BASEINFO_QQ,C.CUSTOMER_WECHAT_NO,
    C.CUSTOMER_BASEINFO_EMAIL,A.DJACK_INTRODUCE
    FROM DJK_DJACK_SPECIEINFO A 
    LEFT JOIN DJK_CUSTOMER_REGISTER B
    ON A.DJACK_SPECIEINFO_ID=B.CUSTOMER_REGISTER_ID
    LEFT JOIN DJK_CUSTOMER_BASEINFO C
    ON B.CUSTOMER_REGISTER_ID=C.CUSTOMER_BASEINFO_ID
	LEFT JOIN DJK_SERVICE_LABLE H
	ON A.DJACK_SPECIEINFO_ID=H.DJACK_ID
    WHERE A.SPECIE_IS_DELETED=0 AND A.DJACK_SPECIEINFO_ID=@DJKID) T
	LEFT JOIN DJK_COUNTRY_CITY D
	ON T.CUSTOMER_COUNTRY_ID=D.COUNTRY_CITY_ID) T1
	LEFT JOIN DJK_COUNTRY_CITY E
	ON T1.CUSTOMER_CITY_ID=E.COUNTRY_CITY_ID) T2
	LEFT JOIN DJK_COUNTRY_CITY F
	ON T2.CUSTOMER_DISTINATION_ID=F.COUNTRY_CITY_ID", parmCollection);
            ds.Tables[0].TableName = this.TableName;
            return ds;
        }

        /// <summary>
        /// 查询地接客好人缘
        /// </summary>
        /// <param name="djkId">地接客ID</param>
        /// <returns>HOWELL:邀请人数</returns>
        public DataSet GetDjackHowell(string djkId)
        {
            if (string.IsNullOrEmpty(djkId))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("DJKID", ParameterDirection.Input, EDbType.String, 36, djkId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT COUNT(*) HOWELL
    FROM DJK_CUSTOMER_REGISTER A 
    INNER JOIN DJK_DJACK_SPECIEINFO B
    ON A.CUSTOMER_REGISTER_ID=B.DJACK_SPECIEINFO_ID
    WHERE B.DJACK_SPECIEINFO_ID=@DJKID
    GROUP BY A.CUSTOMER_INVITATION_CODE", parmCollection);
            ds.Tables[0].TableName = this.TableName;
            return ds;
        }

        /// <summary>
        /// 根据地接客ID查询车辆列表
        /// </summary>
        /// <param name="djkId">地接客ID</param>
        /// <returns>DJACK_SPECIEINFO_ID:地接客ID，DJACK_SERVICE_VOICE:服务标签,CUSTOMER_BASEINFO_MOBILE：移动电话，VEHICLE_INFO_ID:车辆ID，VEHICLE_NAME：车辆名称，VEHICLE_BRAND：车辆品牌，VEHICLE_TYPE：车辆类型，VEHICLE_SEATS：车辆座位数，VEHICLE_COLOR：车辆颜色，VEHICLE_SERVICE_TYPE：服务类型，VEHICLE_SERVICE_TIME：服务时间，VEHICLE_PRICE_DAY：价格，VEHICLE_INTRO：车辆简介，VEHICLE_CODE：车辆编码，VEHICLE_SERVICE_AREA：车辆服务范围，VEHICLE_DEFAULT_PIC：车辆图片</returns>
        public DataSet SelectVehicleById(string djkId)
        {
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("DjkId", ParameterDirection.Input, EDbType.String, 36, djkId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT
T.*
,B.CUSTOMER_BASEINFO_MOBILE
FROM (SELECT 
A.VEHICLE_INFO_ID
,A.DJACK_ID DJACK_SPECIEINFO_ID
,A.VEHICLE_NAME
,A.VEHICLE_BRAND
,A.VEHICLE_TYPE
,A.VEHICLE_SEATS
,A.VEHICLE_COLOR
,A.VEHICLE_SERVICE_TYPE
,A.VEHICLE_SERVICE_TIME
,A.VEHICLE_PRICE_DAY
,A.VEHICLE_INTRO
,A.VEHICLE_CODE
,A.VEHICLE_SERVICE_AREA
,A.VEHICLE_DEFAULT_PIC
FROM DJK_VEHICLE_INFO A
WHERE A.DJACK_ID=@DjkId) T
LEFT JOIN DJK_CUSTOMER_BASEINFO B ON T.DJACK_SPECIEINFO_ID=B.CUSTOMER_BASEINFO_ID", parmCollection);
            ds.Tables[0].TableName = this.TableName;
            return ds;
        }
        #endregion

        #region 地接客信息判断处理
        /// <summary>
        /// 判断是否有该用户
        /// </summary>
        /// <param name="djkId">用户编号</param>
        /// <returns>判断结果</returns>
        public bool IsHasUser(string djkId)
        {
            if (string.IsNullOrEmpty(djkId))
            {
                return false;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("DjkId", ParameterDirection.Input, EDbType.String, 36, djkId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT 1 FROM DJK_CUSTOMER_BASEINFO WHERE CUSTOMER_BASEINFO_ID=@DjkId", parmCollection);
            if (ds.Tables[0].Rows.Count <= 0)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// 根据地接客ID查询地接客旅游推荐
        /// </summary>
        /// <param name="djkId">地接客ID</param>
        /// <returns>DJACK_SPECIEINFO_ID:地接客ID,DJACK_TRAVEL_ADVICE：推荐信息</returns>
        public DataSet GetDjackTravelAdviceById(string djkId)
        {
            if (string.IsNullOrEmpty(djkId))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("DjkId", ParameterDirection.Input, EDbType.String, 36, djkId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT DJACK_SPECIEINFO_ID,DJACK_TRAVEL_ADVICE FROM DJK_DJACK_SPECIEINFO WHERE DJACK_SPECIEINFO_ID=@DjkId", parmCollection);
            ds.Tables[0].TableName = this.TableName;
            return ds;
        }


        /// <summary>
        /// 根据地接客查询地接客信息
        /// </summary>
        /// <param name="djkId">地接客ID</param>
        /// <returns></returns>
        public DataSet GetDjackByDjkId(string djkId)
        {
            if (string.IsNullOrEmpty(djkId))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("DJKID", ParameterDirection.Input, EDbType.String, 50, djkId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT * FROM DJK_DJACK_SPECIEINFO WHERE DJACK_SPECIEINFO_ID =@DJKID", parmCollection);
            ds.Tables[0].TableName = this.TableName;
            return ds;
        }

        /// <summary>
        /// 判断用户昵称是否唯一
        /// </summary>
        /// <param name="userNickName">用户昵称</param>
        /// <param name="id">用户编号</param>
        /// <returns>用户昵称是否唯一(true:唯一，false:不唯一)</returns>
        public bool IsNickNameUnique(string userNickName, string djkId)
        {
            if (string.IsNullOrEmpty(djkId) ||
                string.IsNullOrEmpty(userNickName))
            {
                return false;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("UserName", ParameterDirection.Input, EDbType.String, 36, userNickName.Replace("'", "").Replace(",", "','")));
            parmCollection.Add(new CDbParm("DjkId", ParameterDirection.Input, EDbType.String, 36, djkId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT 1 FROM DJK_CUSTOMER_REGISTER 
    WHERE CUSTOMER_NICK=@UserName AND CUSTOMER_REGISTER_ID<>@DjkId", parmCollection);
            if (ds.Tables[0].Rows.Count <= 0)
            {
                return false;
            }
            return true;
        }

        #endregion

        #region  成为地接客相关处理
        #region 查询注册信息
        /// <summary>
        /// 根据编号查询用户注册信息
        /// </summary>
        /// <param name="registerId">注册信息编号</param>
        /// <returns>查询结果</returns>
        public DataSet GetUserRegisterInfoById(string registerId)
        {
            if (string.IsNullOrEmpty(registerId))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("RegisterId", ParameterDirection.Input, EDbType.String, 36, registerId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT A.CUSTOMER_REGISTER_ID,A.CUSTOMER_REGISTER_ACCOUNT,
    A.CUSTOMER_REGISTER_PWD,A.CUSTOMER_REGISTER_TIME,A.CUSTOMER_ACCOUNT_TYPE,A.CUSTOMER_NICK,
    A.CUSTOMER_CLIENT_CODE,A.ACCOUNT_USING_STATUS,A.ACCOUNT_LOGIN_STATUS,A.CUSTOMER_DEFAULT_PIC,A.CUSTOMER_SOURCE_PIC,
    A.ACCOUNT_ACTIVATION_CODE,A.ACCOUNT_IS_ACTIVATED,A.BE_INVITATION_CODE,A.CUSTOMER_INVITATION_CODE,
    A.ACCOUNT_REGISTER_IP,A.ACCOUNT_IS_DELETED,A.CUSTOMER_ACCOUNT_RMK
    FROM DJK_CUSTOMER_REGISTER A
    WHERE A.CUSTOMER_REGISTER_ID=@RegisterId", parmCollection);
            CBizCustomerRegister register = new CBizCustomerRegister();
            ds.Tables[0].TableName = register.TableName;
            return ds;
        }

        /// <summary>
        /// 判断用户注册信息是否有变动
        /// </summary>
        /// <param name="ds1">注册信息</param>
        /// <param name="registerId">用户注册ID</param>
        /// <param name="headPhotoName">头像名称</param>
        /// <param name="nickName">昵称</param>
        /// <returns>判断结果  -1：用户注册信息变动；1：用户注册信息未变动</returns>
        public int ConfirmRegisterInfo(DataSet ds, string headPhotoName, string nickName)
        {
            if (Convert.ToInt32(ds.Tables[0].Rows[0]["ACCOUNT_IS_ACTIVATED"]) == 0)
            {
                return -10;//成为地接客失败，用户账号未激活
            }
            if (ds.Tables[0].Rows[0]["CUSTOMER_DEFAULT_PIC"].ToString() != headPhotoName ||
                ds.Tables[0].Rows[0]["CUSTOMER_NICK"].ToString() != nickName)
            {
                return -1;
            }
            return 1;
        }

        /// <summary>
        /// 判断用户昵称是否唯一
        /// </summary>
        /// <param name="userNickName">用户昵称</param>
        /// <param name="userId">用户编号</param>
        /// <returns>用户昵称是否唯一(true:唯一，false:不唯一)</returns>
        public DataSet IsNickNameUniques(string userNickName, string userId)
        {
            if (string.IsNullOrEmpty(userId) ||
                string.IsNullOrEmpty(userNickName))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("UserName", ParameterDirection.Input, EDbType.String, 36, userNickName.Replace("'", "").Replace(",", "','")));
            parmCollection.Add(new CDbParm("UserId", ParameterDirection.Input, EDbType.String, 36, userId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT 1 FROM DJK_CUSTOMER_REGISTER 
WHERE CUSTOMER_NICK=@UserName AND CUSTOMER_REGISTER_ID<>@UserId", parmCollection);
            CBizCustomerRegister register = new CBizCustomerRegister();
            ds.Tables[0].TableName = register.TableName;
            return ds;
        }

        #endregion

        #region 查询用户基本信息

        /// <summary>
        /// 根据编号查询用户基本信息
        /// </summary>
        /// <param name="registerId">注册信息编号</param>
        /// <returns>查询结果</returns>
        public DataSet GetBaseInfoById(string baseInfoId)
        {
            if (string.IsNullOrEmpty(baseInfoId))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("BaseInfoId", ParameterDirection.Input, EDbType.String, 36, baseInfoId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT CUSTOMER_BASEINFO_ID,CUSTOMER_BASEINFO_NAME,CUSTOMER_BASEINFO_GENDER,
    CUSTOMER_CREDENTIALS_TYPE,CUSTOMER_CREDENTIALS_NO,
	CUSTOMER_BASEINFO_BIRTH,CUSTOMER_DISTINATION_ID,CUSTOMER_CITY_ID,CUSTOMER_COUNTRY_ID,CUSTOMER_BASEINFO_MOBILE,
    CUSTOMER_BASEINFO_PHONE,CUSTOMER_BASEINFO_QQ,CUSTOMER_WECHAT_NO,CUSTOMER_BASEINFO_FAX,CUSTOMER_BASEINFO_EMAIL,
	CUSTOMER_BASEINFO_INTRO,BASEINFO_IS_DELETED,BASEINFO_IS_DISPLAY,CUSTOMER_BASEINFO_RMK
    FROM DJK_CUSTOMER_BASEINFO WHERE CUSTOMER_BASEINFO_ID=@BaseInfoId", parmCollection);
            CBizCustomerBaseInfo baseInfo = new CBizCustomerBaseInfo();
            ds.Tables[0].TableName = baseInfo.TableName;
            return ds;
        }

        /// <summary>
        /// 判断用户基本信息是否有变动
        /// </summary>
        /// <param name="ds1">原用户基本信息</param>
        /// <param name="id">用户ID</param>
        /// <param name="phone">移动电话</param>
        /// <param name="mobilePhone">固定电话</param>
        /// <param name="name">名称</param>
        /// <param name="gender">性别</param>
        /// <param name="credentialsNum">证件号码</param>
        /// <returns>判断结果  -1：用户基本信息变动；1：用户基本信息未变动</returns>
        public int ConfirmBaseInfo(DataSet ds, string phone, string mobilePhone, string name, string gender, string credentialsNum, string distinId, string cityId, string countryId)
        {
            if (ds.Tables[0].Rows[0]["CUSTOMER_BASEINFO_PHONE"].ToString() != phone ||
                ds.Tables[0].Rows[0]["CUSTOMER_BASEINFO_MOBILE"].ToString() != mobilePhone ||
                ds.Tables[0].Rows[0]["CUSTOMER_BASEINFO_NAME"].ToString() != name ||
                ds.Tables[0].Rows[0]["CUSTOMER_BASEINFO_GENDER"].ToString() != gender ||
                ds.Tables[0].Rows[0]["CUSTOMER_CREDENTIALS_NO"].ToString() != credentialsNum ||
                ds.Tables[0].Rows[0]["CUSTOMER_DISTINATION_ID"].ToString() != distinId ||
                ds.Tables[0].Rows[0]["CUSTOMER_CITY_ID"].ToString() != cityId ||
                ds.Tables[0].Rows[0]["CUSTOMER_COUNTRY_ID"].ToString() != countryId
                )
            {
                return -1;
            }
            return 1;
        }

        #endregion

        #endregion


        public DataSet GetAllDjack()
        {
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT * FROM DJK_DJACK_SPECIEINFO");
            ds.Tables[0].TableName = this.TableName;
            return ds;
        }

        /// <summary>
        /// 修改 交易数量true 为自增长1
        /// </summary>
        /// <param name="djkid">要修改的地接客id</param>
        /// <returns>string[]</returns>
        /// Author:蒲崇彬
        /// Creation date:2015-6-3
        public string[] UpdateDjackStatus(string djkid)
        {
            DataSet ds = GetDjackByDjkId(djkid);
            if (ds == null)
            {
                return new string[] { "false", "该用户不存在" };
            }

            ds.Tables[0].Rows[0]["DJACK_TRADING_NUMBER"] = Convert.ToInt32(ds.Tables[0].Rows[0]["DJACK_TRADING_NUMBER"]) + 1;

            this.Update(ds);
            return new string[] { "true", "修改成功" };
        }

        #region 搜索地接客
        public System.Collections.Generic.Dictionary<string, string> dicQuery = new System.Collections.Generic.Dictionary<string, string>();
        public void SetQueryStr(string strpQuery)
        {
            System.Collections.Generic.List<string[]> lsTem = (from p in strpQuery.Split('&')
                                                               where p.IndexOf("=") != -1
                                                               select
                                                               p.Split('=')).Distinct().ToList();
            if (lsTem.Count > 0)
            {
                lsTem.ForEach(delegate(string[] item)
                {
                    dicQuery.Add(item[0], item[1]);
                });
            }
        }

        public DataSet GetDjackList(string strf, int currentPage, int pageSize)
        {
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("wherefilter", ParameterDirection.Input, EDbType.String, 255, strf));
            parmCollection.Add(new CDbParm("ipagenum", ParameterDirection.Input, EDbType.Integer, 5, currentPage));
            parmCollection.Add(new CDbParm("ipagerows", ParameterDirection.Input, EDbType.Integer, 5, pageSize));

            DataSet ds = this.DataObj.QueryBySP("DJK_SELECT_DJACK_SEARCH_FOR_VIEW", parmCollection);

            return ds;
        }
        #endregion
    }
}
